package com.itheima.d3_synchronized_code.explain;

import com.itheima.d2_thread_safe.Account;

/**
 * 目标：模拟线程安全问题。
 */
public class ThreadTest {
    public static void main(String[] args) {
        //1. 账户对象
//        Account account = new Account("001",100000.0);
//        new Thread(()->{account.drawMoney(100000);},"马走日").start();
//        new Thread(()->{account.drawMoney(100000);},"马邦德").start();
        /**
         * 马走日取款成功
         * 马邦德取款成功
         * 账户余额 = 0.0
         * 账户余额 = -100000.0
         */
            com.itheima.d2_thread_safe.Account account = new Account("001",100000.0);
            for (int i = 0; i < 100; i++) {
                new Thread(()->{account.drawMoney(100000);},"县长").start();
                new Thread(()->{account.drawMoney(100000);},"马邦德").start();
        }
    }
}

